package com.flyco.modules.oms.entity;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import com.flyco.poi.excel.annotation.Excel;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

/**
 * @Description: 订单明细
 * @Author: flyco
 * @Date: 2019-12-10
 * @Version: V1.0
 */
@Data
@TableName("oms_order_item")
public class OmsOrderItem implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    @Excel(name = "订单编号", width = 15)
    private String orderId;
    /**
     * 订单编号
     */
    private String orderSn;
    /**
     * 商品id
     */
    @Excel(name = "商品编号", width = 15)
    private Long productId;
    /**
     * 商品图片
     */
    private String productPic;
    /**
     * 商品货号
     */
    @Excel(name = "商品货号", width = 15)
    private String productSn;
    /**
     * 商品名称
     */
    @Excel(name = "商品名称", width = 25)
    private String productName;
    /**
     * 商品品牌
     */
    @Excel(name = "商品品牌", width = 15)
    private String productBrand;
    /**
     * 订单商品类型，0：普通商品，1：赠品
     */
    @Excel(name = "是否赠品", width = 15, dicCode = "yn")
    private String orderProductType;
    /**
     * 销售价格
     */
    @Excel(name = "销售价格", width = 15)
    private java.math.BigDecimal productPrice;
    /**
     * 需求箱数
     */
    @Excel(name = "购买数量", width = 15)
    private Integer productQuantity;
    /*需求箱数
    public Integer getProductQuantity() {
        try {
            return (int) this.productQuantity / this.productSkuSpec;
        } catch (Exception e) {
            return 0;
        }
    }*/

    @Excel(name = "赠品数量", width = 15)
    private Integer giftQuantity;
    /**
     * 发货数量
     */
    private BigDecimal sendQty;

    /**
     * 发货数量（换算成最小包装单位后的）
     */
    private Integer sendProQty;
    /**
     * 入库数量
     */
    private Integer receiveQty;
    /**
     * 商品sku编号
     */
    @Excel(name = "商品sku编号", width = 15)
    private Long productSkuId;
    /**
     * 商品sku条码
     */
    @Excel(name = "商品sku条码", width = 15)
    private String productSkuCode;
    /**
     * 售卖单位
     */
    @Excel(name = "售卖单位", width = 15)
    private String productSkuUnit;
    /**
     * 单位
     */
    @Excel(name = "单位", width = 15)
    private String productUnit;
    /**
     * SAP物料编号
     */
    private String sapItemCode;
    /**
     * 商品分类id
     */
    private Long productCategoryId;
    /**
     * 商品的销售属性
     */
    private String sp1;
    /**
     * sp2
     */
    private String sp2;
    /**
     * sp3
     */
    private String sp3;
    /**
     * 商品促销名称
     */
    private String promotionName;
    /**
     * 商品促销分解金额
     */
    private java.math.BigDecimal promotionAmount;
    /**
     * 优惠券优惠分解金额
     */
    private java.math.BigDecimal couponAmount;
    /**
     * 积分优惠分解金额
     */
    private java.math.BigDecimal integrationAmount;
    /**
     * 该商品经过优惠后的分解金额
     */
    private java.math.BigDecimal realAmount;
    /**
     * 商品赠送积分
     */
    private Integer giftIntegration;
    /**
     * 商品赠送成长值
     */
    private Integer giftGrowth;
    /**
     * 商品销售属性:[{"key":"颜色","value":"颜色"},{"key":"容量","value":"4G"}]
     */
    private String productAttr;
    /**
     * 外部来源类型：ad,cps,ref
     */
    private String netSourceType;
    /**
     * 一级来源(keyname)
     */
    private String netSourceArg1;
    /**
     * 二级来源(keysource)
     */
    private String netSourceArg2;
    /**
     * 三级来源
     */
    private String netSourceArg3;
    /**
     * 四级来源
     */
    private String netSourceArg4;
    /**
     * 来源明细
     */
    private String netSourceArgdetail;
    /**
     * 商品促销金额
     */
    private java.math.BigDecimal totalPromotionAmount;
    /**
     * 优惠券优惠金额
     */
    private java.math.BigDecimal totalCouponAmount;
    /**
     * 积分优惠金额
     */
    private java.math.BigDecimal totalIntegrationAmount;
    /**
     * 红包优惠金额
     */
    private java.math.BigDecimal totalRedbagAmount;
    /**
     * 小计金额(单价*数量-促销-优惠券-积分-红包)
     */
    private java.math.BigDecimal totalRealAmount;
    /**
     * 订单明细商品金额小计(单价*数量)
     */
    private java.math.BigDecimal totalProductAmount;
    /**
     * 申请退货数量
     */
    private Integer returnApplyQuantity;
    /**
     * 实际退货数量
     */
    private Integer returnRealQuantity;

    /**
     * 售后申请时和该商品同组的其他商品id，多个用逗号分隔
     */
    private String returnGroupIds;
    /**
     * 来源类型：默认值，normal
     */
    private String itemSourceType;
    /**
     * 来源数据集(json)
     */
    private String itemSourceData;
    /**
     * 来源id(Long)
     */
    private Long itemSourceId;
    /**
     * 来源id(String)
     */
    private String itemSourceIdS;

    @TableField(exist = false)
    private String orderProductType_dictText;

    @TableField(exist = false)
    private Integer stock;

    @TableField(exist = false)
    private Integer stockUnit;

    //规格
    private Integer productSkuSpec;

    //购买数量（换算成最小包装单位后的）
    private Integer minUnitQuantity;
    //换算成最小包装单位后的单价
    @TableField(exist = false)
    private BigDecimal minUnitPrice;

    @ApiModelProperty(value = "箱规")
    @TableField(exist = false)
    private String boxUnit;

    public String getBoxUnit() {
        return this.productSkuSpec + this.productUnit + "/" + this.productSkuUnit;
    }

    /**
     * 货物优惠比例
     */
    private java.math.BigDecimal productDiscountRate;
    /**
     * 货物优惠金额
     */
    private java.math.BigDecimal productDiscountAmount;
    /**
     * 促销优惠比例
     */
    private java.math.BigDecimal promotionDiscountRate;
    /**
     * 促销优惠金额
     */
    private java.math.BigDecimal promotionDiscountAmount;
    /**
     * 任务达成优惠比例
     */
    private java.math.BigDecimal missionDiscountRate;
    /**
     * 任务达成优惠金额
     */
    private java.math.BigDecimal missionDiscountAmount;
    /**
     * 调价补差优惠比例
     */
    private java.math.BigDecimal adjustDiscountRate;
    /**
     * 调价补差优惠金额
     */
    private java.math.BigDecimal adjustDiscountAmount;
    /**
     * 固定优惠比例
     */
    private java.math.BigDecimal fixedDiscountRate;
    /**
     * 固定优惠金额
     */
    private java.math.BigDecimal fixedDiscountAmount;

    /**
     * 该商品的折扣总和（只用来在前端展示用）
     */
    @TableField(exist = false)
    private java.math.BigDecimal discountAmount;

    public BigDecimal getDiscountAmount() {
        BigDecimal discountAmount = BigDecimal.ZERO;
        if (getFixedDiscountAmount() != null && getFixedDiscountAmount() != BigDecimal.ZERO) {
            discountAmount = discountAmount.add(getFixedDiscountAmount());
        }
        if (getMissionDiscountAmount() != null && getMissionDiscountAmount() != BigDecimal.ZERO) {
            discountAmount = discountAmount.add(getMissionDiscountAmount());
        }
        if (getProductDiscountAmount() != null && getProductDiscountAmount() != BigDecimal.ZERO) {
            discountAmount = discountAmount.add(getProductDiscountAmount());
        }
        if (getPromotionDiscountAmount() != null && getPromotionDiscountAmount() != BigDecimal.ZERO) {
            discountAmount = discountAmount.add(getPromotionDiscountAmount());
        }
        if (getAdjustDiscountAmount() != null && getAdjustDiscountAmount() != BigDecimal.ZERO) {
            discountAmount = discountAmount.add(getAdjustDiscountAmount());
        }
        return discountAmount;
    }

    /**
     * 应付金额（只用来在前端展示用）
     */
    @TableField(exist = false)
    private java.math.BigDecimal needPayAmount;

    /*对应付金额进初始化
    public BigDecimal getNeedPayAmount() {
        try {
            return new BigDecimal(this.getMinUnitQuantity()).multiply(this.getMinUnitPrice()).subtract(getDiscountAmount());
        } catch (Exception e) {
            return BigDecimal.ZERO;
        }
    }*/

    @TableField(exist = false)
    private BigDecimal maxDiscount;

    @TableField(exist = false)
    private String orderNo;
}
